package com.Maykk.Demo02;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;

/**
 * @ClassName: SendUDP
 * @Description: TODO UDP发送练习
 * @Author: MaykkStar@163.com
 */
public class SendUDP {
    public static void main(String[] args) throws IOException {
        // 实例化发送对象
        DatagramSocket ds = new DatagramSocket();
        // 创建数据
        byte[] bytes = "Hello JavaSE UDP Network ~".getBytes();
        int length = bytes.length;
        InetAddress address = InetAddress.getByName("Star");
        int port = 9527;
        DatagramPacket dp = new DatagramPacket(bytes, length, address, port);
        // 发送
        ds.send(dp);
        // 关闭
        ds.close();
    }
}
